package edu.del.springbootredisbusinesspractice.commons.exception;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice(basePackages = "edu.del.springbootredisbusinesspractice.web.controller")
public class GlobalExceptionAdvice {
    @ExceptionHandler(GlobalException.class)
    public ResponseEntity<?> handleGlobalException(GlobalException e) {
        log.error("全局异常：{}", e.getMessage());
        return ResponseEntity.status(e.getErrorCode()).body(e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public ResponseEntity<?> handleException(Exception e) {
        log.error("服务器内部错误：{}", e.getMessage());
        return ResponseEntity.status(500).body("服务器内部错误");
    }
}
